{% load comments %}
{% load signup_extras %}

<a id="comments"></a><h3>{{ constituency.name }} discussion</h3>
{% if can_post %}
{% if not user.is_anonymous %}{% if user.is_active %}
<p class="quiet">Discuss with other people what you're doing in this constituency.</p>

<script>
function update_notify()
{
    /*state = $('input#notify').value;
    alert(state);*/
    $('#notifyform').submit();
}
</script>

{% with notify_object as notify %}
  <form method="post" id="notifyform">
    <input type="hidden" name="notifypost" value="1"/>
    <label for="notify">Email me when someone posts here</label>
    {% if notify %}
         <input name="notify" type="checkbox" value="yes" {% ifnotequal notify.notify_type 0 %}checked{% endifnotequal %} onchange="update_notify()"/>
    {% else %}
         <input name="notify" type="checkbox" value="yes" onchange="update_notify()"/>
    {% endif %}
    <input type="submit" value="save"/>
  </form>
{% endwith %}

{% get_comment_form for constituency as form %}
<form action="{% comment_form_target %}" method="post" id="post-comment">
  {{ form.content_type }}
  {{ form.object_pk }}
  {{ form.timestamp }}
  {{ form.security_hash }}
  <input type="hidden" name="next" value="{{ request.path }}#comments" />
  <input id="id_comment" name="comment" value="write here" onfocus="if(this.value=='write here') { this.value='' }" onblur="if(this.value==''){ this.value='write here'; }" maxlength="3000" type="text"> <input name="post" class="submit-post" value="post" type="submit">

  <p style="display: none; margin:0;">
    <label for="id_honeypot">If you enter anything in this field your comment will be treated as spam</label> {{ form.honeypot }}
  </p>
</form>
{% endif %}{% endif %}
{% endif %}

{% get_comment_list for constituency as comment_list %}
<div class="comments">
{% for comment in comment_list reversed %}
    <div class="comment">
        {#{% ifequal comment.user user %}<a href='#' style="float:right;">delete</a>{% endifequal %}#}
        {% if perms.delete_comment %}<a href='{% url custom_comment_delete comment.id,request.path %}' class="comment_action">delete</a>{% endif %}
        {% ifequal comment.removal_reason 'none' %}
            <span class="poster">{{ comment.user.display_name }}</span>
            <span class="text">{{ comment.comment }}</span>
        {% else %}
            <span class="text moderated">This comment was removed because: <a href='/moderation/#{{ comment.removal_reason }}'>{{ comment.long_removal_reason }}</a>.</span>
        {% endifequal %}
        <span class="time">{{ comment.submit_date|naturalTimeDifference }}</span>
    </div>
{% empty %}
    <div class="comment">There are no messages for {{ constituency.name }} yet{% if can_post %}, be the first!{% endif %}</div>
{% endfor %}
</div>
